package com.sun.mybatisplus.controller;

import com.sun.mybatisplus.bean.R;
import com.sun.mybatisplus.bean.User;
import com.sun.mybatisplus.bean.UserExt;
import com.sun.mybatisplus.service.UserExtService;
import com.sun.mybatisplus.service.UserService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/mybatis/")
@Transactional(rollbackFor = Exception.class)
public class MybatisPlusContrller {

    @Resource
    private UserService userService;

    @Resource
    private UserExtService userExtService;

    @RequestMapping("/addData")
    public R addData(@RequestBody List<User> user)  {

        String succ = userService.addData(user);
        System.out.println("succ={}" + succ);


        R r = new R<String>();
        r.setCode("200");
        r.setMsg("成功了");
        r.setData("success");
        return r;
    }

    @RequestMapping("/addData2")
    public R addData2(@RequestBody UserExt user) {
        userExtService.addData(user);
        R r = new R<String>();
        r.setCode("200");
        r.setMsg("成功了");
        r.setData("success");
        return r;
    }

    @RequestMapping("/selUserById")
    public R selUserById(Long id) {
        System.out.println("1111111");
        return R.ok(userService.selUserById(id));
    }
}
